#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1e5+10,MOD=1e9+7;
int n,m,_mi[17],_log[MAXN],cnt;
struct UFS
{
	int fa[MAXN];
	void init()
	{
		for(int i=1;i<=n;++i)fa[i]=i;
	}
	int getfa(int x)
	{
		return fa[x]==x?x:fa[x]=getfa(fa[x]);
	}
	void merge(int x,int y)
	{
		int a=getfa(x),b=getfa(y);
		if(a!=b)fa[a]=b;
		return;
	}
}ST[17];
int qpow(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=(LL)a*a%MOD)
		if(b&1)ret=(LL)ret*a%MOD;
	return ret;
}
int main()
{
	freopen("in.in","r",stdin);
	n=read();m=read();
	for(int i=2;i<=n;++i)_log[i]=_log[i>>1]+1;
	_mi[0]=1;
	for(int i=1;i<=16;++i)_mi[i]=_mi[i-1]<<1;
	for(int i=0;i<=_log[n];++i)ST[i].init();
	while(m--)
	{
		int l1=read(),r1=read(),l2=read(),r2=read(),k=_log[r1-l1+1];
		ST[k].merge(l1,l2);
		ST[k].merge(r1-_mi[k]+1,r2-_mi[k]+1);
	}
	for(int i=_log[n];i;--i)
		for(int j=1;j+_mi[i]-1<=n;++j)
		{
			int k=ST[i].getfa(j);
			ST[i-1].merge(j,k);
			ST[i-1].merge(j+_mi[i-1],k+_mi[i-1]);
		}
	for(int i=1;i<=n;++i)
		if(ST[0].getfa(i)==i)
			++cnt;
	LL ans=(LL)qpow(10,cnt-1)*9%MOD;
	printf("%d\n",int(ans));
	return 0;
}
